<?php
$cs = Yii::app()->getClientScript();
$cs->registerCSSFile(Yii::app()->request->baseUrl . '/css/mobile/booking_find.css');
?>
<div data-role='page' id='demo-page'>
    <div data-role="header">
        <a href="#left-panel" class="ui-btn ui-icon-bars ui-btn-icon-notext ui-corner-all">Menu</a>
        <h1>预订场地-<?php echo Blyn::app()->getActiveSpace()->getName(); ?></h1>
    </div>
    <div data-role='content' id='mainContent' style="padding: 5px;">
        <?php
        $screen = Blyn::app()->getUIManager()->getCurrentScreen();
        $wxControl = $screen->getChildControl('BUIWXControl_1');
        $wxControl->renderView('booking_home', array());
        ?>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#fastSearch").click(function() {
                    $("#fastSearch_input").attr("checked", "checked");
                    $("form[name=search_form]").submit();
                });
                $("#search").click(function() {
                    $("#search_input").attr("checked", "checked");
                    $("form[name=search_form]").submit();
                });
                $("#panel_btn_search").click(function() {
                    $("#div_search").css("display", "block");
                    $("#div_categories").css("display", "none");
                });
                $("#panel_btn_categories").click(function() {
                    $("#div_search").css("display", "none");
                    $("#div_categories").css("display", "block");
                });
                $(".up").click(function() {
                    $("#div_search").css("display", "none");
                    $("#div_categories").css("display", "none");
                });
            });
        </script>
        <?php $searchUrl = $wxControl->getLinkUrl(array('name' => 'search', 'id' => 'search')); ?>
        <?php
        $cityList = Blyn::app()->getActiveApp()->getCityList();
        $model = new BDynamicFormModel();
        $model->addField('findText');
        $model->addField('userCity');
        $model->addField('fastSearch_input');
        $model->addField('search_input');
        //by default, set user city to ChongQing
        $model->userCity = 'china.chongqing';

        $savedUserCity = Blyn::app()->getCurrentUser()->getAttribute('myCity_app' . Blyn::app()->getActiveApp()->getId());
        if ($savedUserCity instanceof BAttribute) {
            $model->userCity = Blyn::app()->getCurrentUser()->getAttribute('myCity_app' . Blyn::app()->getActiveApp()->getId())->getValue();
        }

        if ($_POST != NULL && isset($_POST['BDynamicFormModel'])) {
            $model->attributes = $_POST['BDynamicFormModel'];
        }

        if (!$savedUserCity instanceof BAttribute || $savedUserCity->getValue() != $model->userCity) {
            Blyn::app()->getCurrentUser()->addAttribute('myCity_app' . Blyn::app()->getActiveApp()->getId(), $model->userCity);
        }
        ?>
        <div id="div_search" class="div_box" style="display: none;">
            <!--<div class="div_up"><img class="up" src="data:image/svg+xml;charset=US-ASCII,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22iso-8859-1%22%3F%3E%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%20%20width%3D%2214px%22%20height%3D%2214px%22%20viewBox%3D%220%200%2014%2014%22%20style%3D%22enable-background%3Anew%200%200%2014%2014%3B%22%20xml%3Aspace%3D%22preserve%22%3E%3Cpolygon%20points%3D%222.051%2C10.596%207%2C5.646%2011.95%2C10.596%2014.07%2C8.475%207%2C1.404%20-0.071%2C8.475%20%22%2F%3E%3C%2Fsvg%3E" width="14" height="14"/></div>-->
            <?php echo CHtml::beginForm($searchUrl, 'post', array('name' => 'search_form')) ?>
            <fieldset class="ui-grid-a grid1">
                <div class="ui-block-a"><?php echo CHtml::activeTextField($model, 'findText', array('class' => '')); ?></div>
                <div class="ui-block-b"><?php echo CHtml::activeDropDownList($model, 'userCity', $cityList, array('class' => 'span2 ui-mini')); ?></div>
            </fieldset>
            <input type="radio" name="BDynamicFormModel[findType]" id="fastSearch_input" value="" style="display: none;"/>
            <input type="radio" name="BDynamicFormModel[findType]" id="search_input" value="full" style="display: none;"/>
            <fieldset class="ui-grid-a grid2">
                <div class="ui-block-a"><button id="fastSearch" class="ui-btn ui-mini ui-corner-all ui-shadow ui-btn-active">快速查找</button></div>
                <div class="ui-block-b"><button id="search" class="ui-btn ui-mini ui-corner-all ui-shadow ui-btn-active">更新并查找</button></div>
            </fieldset>       
            <?php echo CHtml::endForm() ?>
        </div>
        <div id="div_categories" class="div_box" style="display: none;">
            <!--<div class="div_up"><img class="up" src="data:image/svg+xml;charset=US-ASCII,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22iso-8859-1%22%3F%3E%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%20%20width%3D%2214px%22%20height%3D%2214px%22%20viewBox%3D%220%200%2014%2014%22%20style%3D%22enable-background%3Anew%200%200%2014%2014%3B%22%20xml%3Aspace%3D%22preserve%22%3E%3Cpolygon%20points%3D%222.051%2C10.596%207%2C5.646%2011.95%2C10.596%2014.07%2C8.475%207%2C1.404%20-0.071%2C8.475%20%22%2F%3E%3C%2Fsvg%3E" width="14" height="14"/></div>-->
            <?php $wxControl->renderView('booking_find_summary_1', array()); ?>
        </div>
        <?php
        if (isset($findText)) {
            $data = array(
                'findText' => $findText
            );
            if (isset($findContext)) {
                $data['findContext'] = $findContext;
            }
            $wxControl->renderView('booking_list_1', $data);
        }
        ?>
    </div><!-- /main -->
    <div data-role="footer" data-position="fixed">
        <div data-role="navbar">
            <ul>
                <li><a href="#" id="find" data-icon="search" class="ui-btn-active">分类查询</a></li>
                <li><a href="#" id="mybooking" data-icon="shop">我的预订</a></li>
                <li><a href="#" data-icon="gear">其他</a></li>
            </ul>
        </div><!-- /navbar -->
    </div><!-- /footer -->
    <div data-role="panel" id="left-panel">
        <ul data-role="listview">
            <li data-icon="delete"><a href="#" data-rel="close">关闭</a></li>
            <li data-icon="search"><a href="#" id="panel_btn_search">查询</a></li>
            <li data-icon="bullets"><a href="#" id="panel_btn_categories">分类</a></li>
        </ul>
    </div><!-- /panel -->      
</div>
<script type="text/javascript">
    $(document).ready(function() {
<?php
if (isset($controlPanel)) {
    if ($controlPanel = 'search') {
        ?>
                $("#div_search").css("display", "block");
                $("#div_categories").css("display", "block");
    <?php } else if ($controlPanel = 'categories') {
        ?>
                $("#div_search").css("display", "none");
                $("#div_categories").css("display", "block");
    <?php } else {
        ?>
                $("#div_search").css("display", "none");
                $("#div_categories").css("display", "none");
        <?php
    }
}
?>
    });
</script>